#pragma once

#include <GLcommon/GLDispatch.h>
#include <GLcommon/GLEScontext.h>
#include <GLcommon/objectNameManager.h>
#include <list>



class GLESv2Context : public GLEScontext{
public:
    void init();
    GLESv2Context();
    virtual ~GLESv2Context();
    void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
    int  getMaxTexUnits();

    // This whole att0 thing is about a incompatibility between GLES and OpenGL.
    // GLES allows a vertex shader attribute to be in location 0 and have a
    // current value, while OpenGL is not very clear about this, which results
    // in each implementation doing something different.
    void setAttribute0value(float x, float y, float z, float w);
    void insertTextures(GLuint tex) {m_textures.push_back(tex); }
    void insertBuffers(GLuint buf)  { m_buffers.push_back(buf); }
    void insertFramebufffers(GLuint frameBuf) { m_framebuffers.push_back(frameBuf);}
    void insertRenderBuffers(GLuint renderBuf) { m_renderbuffers.push_back(renderBuf);}
    void insertPrograms(GLuint pro) { m_programs.push_back(pro);}
    void insertShaders(GLuint sha) { m_shaders.push_back(sha);}
    void delTextures(GLuint tex) { m_textures.remove(tex);}
    void delBuffers(GLuint buf) {m_buffers.remove(buf);}
    void delFramebuffers(GLuint frameBuf) {m_framebuffers.remove(frameBuf);}
    void delRenderBufffers(GLuint renderBuf) {m_renderbuffers.remove(renderBuf);}
    void delPrograms(GLuint program) { m_programs.remove(program);}
    void delShaders(GLuint sha) { m_shaders.remove(sha);}
    void validateAtt0PreDraw(unsigned int count);
    void validateAtt0PostDraw(void);
    const float* getAtt0(void) {return m_attribute0value;}

protected:
    bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id);
private:
    void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,GLboolean normalized, int pointsIndex = -1);
    void initExtensionString();

    float m_attribute0value[4];
    GLfloat* m_att0Array;
    unsigned int m_att0ArrayLength;
    bool m_att0NeedsDisable;
    std::list<GLuint >    m_programs;
    std::list<GLuint >    m_shaders;
    std::list<GLuint >    m_textures;
    std::list<GLuint >    m_buffers;
    std::list<GLuint >    m_framebuffers;
    std::list<GLuint >    m_renderbuffers;
};